﻿@{
    ViewBag.Title = "会员组价格";
}
@model IEnumerable<DTcms.Model.user_groups>
<form id="form1">
    <div class="div-content">
        @foreach (var item in Model)
        {
            <div class="layui-form-item">
                <label class="layui-form-label">@item.title</label>
                <div class="layui-input-block">
                    <input type="hidden" name="hideDiscount" value="@item.discount" />
                    <input type="hidden" name="hideGroupId" value="@item.id" />
                    <input type="text" name="txtGroupPrice" class="input small" value="0" onkeydown="return checkForFloat(this,event);" /> 元
                    <span class="Validform_checktip">*享受@(item.discount)折优惠</span>
                </div>
            </div>
        }
    </div>
</form>
@section Scripts{    
    <script type="text/javascript">
        var api = parent.layer.getFrameIndex(window.name);//获取父窗体对象
        function submitValue(data) {
            //初始化默认价格
            var sellprice = parseFloat($(data).parent().parent().find("input[name='spec_sell_price']").val()); //获取父对象的销售价
            if (sellprice > 0) {
                $("input[name='txtGroupPrice']").each(function () {
                    var discount = parseFloat($(this).siblings("input[name='hideDiscount']").val()) / 100; //获得折扣
                    $(this).val(ForDight(sellprice * discount, 2)); //计算出价格
                });
            }
            //获取父对象的价格
            var hideGroupPriceStr = $(data).parent().find("input[name='hide_group_price']").val();
            if (hideGroupPriceStr.length > 0) { //如果默认有值则用值来赋值
                var json = $.parseJSON(hideGroupPriceStr);
                for (var i = 0; i < json.length; i++) {
                    $("input[name='hideGroupId'][value='" + json[i].group_id + "']").siblings("input[name='txtGroupPrice']").val(json[i].price);
                }
            }
        }

        //计算及赋值
        function setGroupPrice(data) {
            //组合的会员组价格参数
            var groupPriceStr = '';
            //遍历会员组价格
            $("input[name='txtGroupPrice']").each(function (i) {
                var groupid = $(this).siblings("input[name='hideGroupId']").val();
                groupPriceStr += '{"group_id": "' + groupid + '", "price": "' + $(this).val() + '"}';
                if (i < $("input[name='txtGroupPrice']").length - 1) {
                    groupPriceStr += ",";
                }
            });
            //赋值给父对象隐藏域
            if (groupPriceStr.length > 0) {
                $(data).parent().find("input[name='hide_group_price']").val("[" + groupPriceStr + "]");
            }
            parent.layer.close(api);
            return false;
        }
    </script>
}
